use strict;
use warnings;
use Encode;
use utf8;

my $file = "test2.txt";
my $outfile = "test-out.txt";
# open(my $fh, $file) || die "Can't open file $file: $!";
# open(my $out, '>:utf8', $outfile) || die "Can't open file $outfile: $!";
# select $out;
open(my $fh, '<:utf8', $file) || die "Can't open file $file: $!";
binmode STDOUT, ":utf8";
while (<$fh>) {
    if (/[汉]/) {
        unless (Encode::is_utf8($_)) {
            Encode::_utf8_on($_);
        }
        print $_;
    }
}
